package com.zengqingfa.springboot.redis.delay;

import com.zengqingfa.springboot.redis.delay.entity.Message;
import com.zengqingfa.springboot.redis.delay.entity.Order;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author zengqingfa
 * @className RedisDelayController
 * @description
 * @create 2022/9/24 17:33
 */

@RestController
@RequestMapping("/redis/delay")
public class RedisDelayController {

    @Resource
    private MessageRedisDelayQueue messageRedisDelayQueue;

    @Resource
    private OrderRedisDelayQueue orderRedisDelayQueue;

    private AtomicLong atomicLong=new AtomicLong(1L);

    @GetMapping("/order")
    public Boolean order(@RequestParam("msg") String msg) {
        Order order = new Order(atomicLong.incrementAndGet(),msg,atomicLong.get()+"==="+msg);
        orderRedisDelayQueue.setDelayTasks(order, 5000);
        return Boolean.TRUE;
    }

    @GetMapping("/message")
    public Boolean message(@RequestParam("msg") String msg) {
        Message message = new Message(atomicLong.incrementAndGet(),msg,atomicLong.get()+"==="+msg);
        messageRedisDelayQueue.setDelayTasks(message, 5000);
        return Boolean.TRUE;
    }
}